#include <iostream>
#include <fstream>
#include "BinarySearchTree.h"
using namespace std;

/**
 * @brief print the data by index
 *
 * @tparam T template params
 * @param target Vector<T>
 */
template <typename T>
void print(vector<T>& target){
    for(auto i=target.begin(); i!=target.end(); ++i){
        cout << *i << "\t";
    }
    cout << endl;
}


/**
 * @brief main For test
 *
 * @param args number of args
 * @param argv[] 1: number of generation
 *
 * @return 0
 */
int main(int args, char* argv[]){
    BinarySearchTree<int> a;
    ifstream file;
    time_t start;
    time_t end;


    file.open("number.txt");
    int temp;
    vector<int> target(0);
    while(!file.eof()){
        file >> temp;
        target.push_back(temp);
    }
    cout << "Primary Sequence: " << endl;
    print(target);

    cout << "BST_sort: " << endl;
    start = clock();
    BST_sort(target);
    end = clock();
    double endtime=(double)(end-start)/CLOCKS_PER_SEC;
    cout << "Time consuming: "<< endtime << endl;
    cout << "Result of BST_sort: " << endl;
    print(target);

    cout << "Randomized_BST_sort: " << endl;
    start = clock();
    Randomized_BST_sort(target);
    end = clock();
    endtime=(double)(end-start)/CLOCKS_PER_SEC;
    cout << "Time consuming: "<< endtime << endl;
    cout << "Result of Randomized_BST_sort: " << endl;
    print(target);

    cout << "Result of BST_sort over sorted sequence: " << endl; 
    start = clock();
    BST_sort(target);
    end = clock();
    endtime=(double)(end-start)/CLOCKS_PER_SEC;
    cout << "Time consuming: "<< endtime << endl;
    cout << "Result of BST_sort: " << endl;
    print(target);

    return 0;
}
